<template>

  <!--

    对话框：选择生产任务的工序

    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectTaskProcess.title"
             :visible.sync="dialog_selectTaskProcess.visible"
             width="1100px">
    <!-- 检索条件 -->
    <el-card class="box-card" shadow="hover" style="margin-bottom: 20px;">
      <div slot="header" class="clearfix">
        <span><b>生产任务信息</b></span>
        <el-tooltip content="显示 / 隐藏" placement="top" style="float: right; padding: 3px 0">
          <el-switch
            v-model="fold_form_order"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="false"
            inactive-value="true">
          </el-switch>
        </el-tooltip>
      </div>
      <div v-show="fold_form_order== 'false'">
    <el-form :model="dialog_selectTaskProcess.queryParams"
             :inline="true" v-show="dialog_selectTaskProcess.showSearch" label-width="68px">
      <!-- 订单编号 -->
      <el-form-item label="单据编号" prop="docNum">
        <el-input
          v-model="dialog_selectTaskProcess.queryParams.docNum"
          placeholder="请输入单据编号"
          clearable
          size="small"
          @keyup.enter.native="getList_taskProcess"
        />
      </el-form-item>
      <!-- 订单名称 -->
      <el-form-item label="单据日期" prop="docDt">
        <el-input
          v-model="dialog_selectTaskProcess.queryParams.docDt"
          placeholder="请输入单据日期"
          clearable
          size="small"
          @keyup.enter.native="getList_taskProcess"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_taskProcess">搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 订单列表 -->
    <el-table v-loading="loading" :data="dialog_selectTaskProcess.taskList" row-key="taskUuid">
      <el-table-column label="物料名称" align="center"
                       prop="itemName" width="280" :show-overflow-tooltip="true"/>
      <el-table-column label="物料编号" align="center"
                       prop="itemNum"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="数量" align="center" >
        <template slot-scope="scope">
          <span> {{ Math.floor((scope.row.taskQty)) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" align="center" prop="docNum" width="150"/>
      <el-table-column label="单据日期" align="center" prop="docDt" width="180" />
      <el-table-column label="经办人" align="center" prop="attentionUserName" />
      <el-table-column label="审核人" align="center" prop="confirmUserName" />
      <el-table-column label="工艺编号" align="center" prop="processDocNum" />
      <el-table-column label="工艺版本" align="center" prop="processVersionNum" />
      <el-table-column label="订单编号" align="center" prop="docNum" width="150"/>
      <el-table-column label="订单日期" align="center" prop="docDt" width="120" />
      <el-table-column label="客户名称" align="center" prop="custName" width="160" />
      <el-table-column label="是否完工" align="center" prop="sysYesNoDone" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoDone"/>
        </template>
      </el-table-column>
      <el-table-column label="定额级别" align="center" prop="mesDictQuotaLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_quota_level" :value="scope.row.mesDictQuotaLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="单位时长" align="center" prop="quotaPerMinutes"/>
      <el-table-column label="总时长" align="center" prop="quotaTotalMinutes"/>
      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            type="success" plain
            size="small"
            icon="el-icon-check"
            @click="selectTask_done(scope)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>
      </div>
    </el-card>
    <div style="width: 2px;height: 40px;color: #bfcbd9"></div>
    <!-- 订单明细列表 -->
    <el-card class="box-card" shadow="hover" style="margin-bottom: 20px;">
      <div slot="header" class="clearfix">
        <span><b>工序</b></span>
      </div>
    <el-table v-loading="loading" :data="taskProcesslist" row-key="taskDetailUuid"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="orderNum"/>
      <el-table-column label="工序号" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>
      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>
      <el-table-column label="工序内容" align="center" prop="processContent"/>
      <el-table-column label="是否复制" align="center" prop="sysYesNoCopy">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoCopy"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="sysNormalDisable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.sysNormalDisable"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="docNote"/>
    </el-table>
    </el-card>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="selectTaskDetailsDone">确 定</el-button>
      <el-button @click="dialog_hide_selectTaskProcess">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
import {listTask} from "@/api/mes/tasks";
import {listTaskDetails, listTaskDetailsByTaskUuid} from "@/api/mes/taskDetails";
export default {
  dicts: ['sys_normal_disable','mes_dict_process_name','mes_dict_process_type','sys_yes_no','mes_dict_process_code'],
  props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  },
  data() {
    return {
      dialog_selectTaskProcess: {
        visible: false,
        showSearch: true,
        title: "请选择物料",
        total: 0,
        taskList: [],
        queryParams:{
          pageNum: 1,
          pageSize: 10,
          parentUuid: '0',
          fkProcessDetailUuid: null,
          orderDetailUuid: null,
          selectedAttentionUser:null,
          fkAttentionUserId:null,
          sysYesNoDone: null,
          mesDictQuotaLevel: null,
          quotaPerMinutes: null,
          quotaTotalMinutes: null
        }
      },
      taskProcesslist:[],
      fold_form_order: 'false',
      // 遮罩层
      loading: true,
      show1: false,
      // 遮罩层
      visible: false,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parentUuid: '0',
        roleId: undefined,
        userName: undefined,
        phonenumber: undefined,
        taskUuid: undefined
      },
      selectedUser: {
        id: null,
        nickName: null,
        userName: null
      }
    };
  },
  methods: {


    /** 读取列表：订单 */
    getList_taskProcess() {
      this.loading = true;
      listTask(this.dialog_selectTaskProcess.queryParams).then(response => {
        console.log( response )
        this.dialog_selectTaskProcess.taskList = response.rows;
        this.dialog_selectTaskProcess.total = response.total;
        this.loading = false;
      });
    },
// 显示弹框
    show() {
      this.getList_taskProcess()
      this.dialog_selectTaskProcess.visible = true;
      this.dialog_selectTaskProcess.title = "选择工序";
    },


    // 对话框：隐藏 - 选择物料
    dialog_hide_selectTaskProcess() {
      this.dialog_selectTaskProcess.visible = false;
    },

    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },

    /**读取：订单明细*/
    selectTask_done(scope){
      this.queryParams.fkTaskUuid=scope.row.taskUuid;
      listTaskDetailsByTaskUuid(this.queryParams).then(response => {
        console.log(response)
        this.taskProcesslist = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 多选完成
    selectTaskDetailsDone() {
      this.$emit("ok", this.taskDetailUuids );
      this.dialog_hide_selectTaskProcess()
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection)
      this.taskDetailUuids = selection.map(item => item.taskDetailUuid);
      console.log(this.taskDetailUuids)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList_taskProcess();
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 完成：选择物料
    selectTaskProcess_done(user) {
      console.log(user)
      this.dialog_selectTaskProcess.visible = false;
      this.$emit("ok", user );
    },



  }
};
</script>
